<?php
/**
 * Description of _formupdate
 * 
 * @author Dung.Hoang
 * @since 22-03-2014 - 15:18:30
 */
$menu = $this->parent;
?>
<?php if (Yii::app()->user->hasFlash('noti-form')): ?>
    <?php echo Yii::app()->user->getFlash('noti-form') ?>
<?php endif; ?>
<div class="grid-content">
    <div class="formRow">
        <label for="MenuItem_name" class="required">Kiểu</label>               
        <div class="formRight">
            <select id="Menu_Type" onchange="loadDataByType($(this));" class="span10" name="MenuItem[type]">
                <?php foreach (MenuItem::getArrayType() as $type => $type_name): ?>
                    <option value="<?php echo @$type ?>" 
                            <?php echo @$menu->type == $type ? 'selected=""' : '' ?>>
                                <?php echo $type_name ?>
                    </option>
                <?php endforeach; ?>
            </select>                
        </div>
    </div>
    <div class="formRow">
        <label for="MenuItem_value" class="required">Nội dung</label>               
        <div class="formRight" id="Select_Data">
            <input class="span10" name="MenuItem[value]" id="MenuItem_description" type="text" value="<?php echo @$menu->value ?>">                  
        </div>
    </div>
    <div class="formRow">
        <label for="MenuItem_name" class="required">Tên</label>               
        <div class="formRight">
            <input class="span10" name="MenuItem[name]" id="MenuItem_name" type="text" value="<?php echo @$menu->name ?>">                  
        </div>
    </div>
    <div class="formRow">
        <label for="MenuItem_description" class="required">Mô tả</label>               
        <div class="formRight">
            <input name="MenuItem[description]" id="MenuItem_description" type="text" class="span10" value="<?php echo @$menu->description ?>">                  
        </div>
    </div>
    <div class="formRow">
        <label for="MenuItem_rank" class="required">Thứ hạng</label>               
        <div class="formRight">
            <input name="MenuItem[rank]" class="span10" id="MenuItem_description" type="text"  value="<?php echo @$menu->rank ?>">                  
        </div>
    </div>
    <?php if ($_GET['pk'] != 2): ?>
        <div class="formRow">
            <label for="MenuItem_rank" class="required">Cấp cha</label>               
            <div class="formRight">
                <?php
                $menu_id = $_GET['pk'];
                $name    = "MenuItem[parent_id]";
                $select  = (@$menu->parent_id > 0) ? @$menu->parent_id : 0;
                echo CHtml::dropDownList($name, @$select, MenuItem::getPublicArrayMenu($menu_id), array(
                    'class' => "span10",
                ));
                ?>
            </div>
        </div>
    <?php endif; ?>
</div>
<script>
    loadDataByType();
    function loadDataByType()
    {
        type = $('#Menu_Type').val();
        if (type !== 'link')
        {
            $.ajax({
                url: '<?php echo $this->createUrl('menu/AjaxLoadDataByType', array('lang' => $this->lang)) ?>',
                type: 'post',
                data: {
                    type: type,
                    item_id: '<?php echo @$this->parent->id ?>'
                }
            }).done(function (msg) {
                $('#Select_Data').html('').append(msg);
                $(".chosen-select").chosen();
            });
        }
        else {
            var str = '';
            str += '<input name="MenuItem[value]" id="MenuItem_description" type="text" class="span10" value="<?php echo @$menu->value ?>">'
            $('#Select_Data').html('').append(str);
        }
    }
    function fillName()
    {
        var text = $('#Select_Data select option::selected').attr('menu_name');
        $('#MenuItem_name').val(text);
    }
</script>